package cn.wolfcode.crm.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import cn.wolfcode.crm.domain.Department;
import cn.wolfcode.crm.mapper.DepartmentMapper;
import cn.wolfcode.crm.query.QueryObject;
import cn.wolfcode.crm.service.IDepartmentService;
@Service
public class DepartmentServiceImpl implements IDepartmentService{

	@Autowired
	private DepartmentMapper departmentMapper;

	@Override
	public void saveOrUpdate(Department entity) {
		if (entity.getId() == null) {
			departmentMapper.insert(entity);
		}else {
			departmentMapper.update(entity);
		}
		
	}

	@Override
	public Department get(Long id) {
		return departmentMapper.selectById(id);
	}

	@Override
	public PageInfo<Department> list(QueryObject qo) { 
		PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize());
		List<Department> list = departmentMapper.selectAll(qo);
		return new PageInfo<>(list);
	}

	@Override
	public void delete(Long id) {
		if (id != null) {
			departmentMapper.delete(id);
		}
	}
}
